package fem2.material.cohesive_law2;

import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;

import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

import fem2.Element;
import fem2.ElementManager;
import fem2.StrategyPart;
import fem2.Variable;

/**
 * abstract class for all cohesive law in strong discontinuity modelling
 * 
 * @author hbui
 * 
 */
public abstract class CohesiveLaw extends ElementManager implements StrategyPart {

	protected double Gf; // fracture energy
	protected double ft; // tensile strength

	private Map<Element, ArrayList<Variable>> elementVariable = new TreeMap<Element, ArrayList<Variable>>();

	public CohesiveLaw(double Gf, double ft) {
		this.Gf = Gf;
		this.ft = ft;
	}

	/**
	 * 
	 * @return the tensile strength of material
	 */
	public double getTensileStrength() {
		return ft;
	}

	/**
	 * 
	 * @return fracture energy of material
	 */
	public double getFractureEnergy() {
		return Gf;
	}

	/**
	 * set the variables for element
	 * 
	 * @param e
	 * @param v
	 */
	public void setVariable(Element e, ArrayList<Variable> v) {
		elementVariable.put(e, v);
	}

	/**
	 * get the variables associated with the element
	 * 
	 * @param e
	 * @return
	 */
	public ArrayList<Variable> getVariable(Element e) {
		return elementVariable.get(e);
	}

	/**
	 * get jump traction on discontinuity surface<br>
	 * T = [tn tm]
	 * 
	 * @param e
	 * @param k
	 * @return
	 */
	public abstract IVector getJumpTraction(Element e, int k);

	/**
	 * compute sitffness on jump surface
	 * 
	 * <pre>
	 * 
	 * Ct = 
	 * [		d(tn)/d(wn)	d(tn)/d(wm)
	 * 		d(tm)/d(wn)	d(tm)/d(wm)	]
	 * 
	 * </pre>
	 * 
	 * 
	 * @param e
	 * @param w
	 *            displacement jump = [wn wm]
	 * @return
	 */
	public abstract IMatrix getJumpStiffness(Element e, int k);

	@Override
	public void Initialize(Element e) {

		// int ngc = ((SDAElement) e).getNumGaussPointOnCrack();
		// int wdim = e.getMeshPart().getDimension();
		//
		// ArrayList<Variable> vars = new ArrayList<Variable>();
		//
		// for (int i = 0; i < ngc; i++) {
		// Variable v = new Variable(1);
		//
		// v.registerVectorVariable(VariableName.DISCONTINUITY_JUMP, wdim,
		// false);
		//
		// vars.add(v);
		// }
		//
		// setVariable(e, vars);

	}
}
